Ext.require(['*']);

Ext.onReady(function(){

    Ext.tip.QuickTipManager.init();
    
    Bee.north = Ext.create('Ext.Component', {
        id: 'main-viewport-north',
        region: 'north',
        height: 30,
        margins: '3 5 3 5',
        html: '<h1>欢迎：系统管理员 | 修改密码 | 注销</h1>'
    });
    
    Bee.west = Ext.create('Ext.panel.Panel', {
        id: 'main-viewport-west',
        region: 'west',
        layout: 'accordion',
        title: '',
        split: true,
        width: 180,
        minWidth: 180,
        maxWidth: 180,
        collapsible: true,
        animCollapse: true,
        collapseMode: 'mini',
        margins: '0 0 3 5',
        items: []
    });
    
    Bee.home = Ext.create('Ext.panel.Panel', {
        id: 'main-viewport-center-home',
        title: '首页',
        layout: 'fit',
        loader: {
            url: 'panel/home.html',
            autoLoad: true,
            scripts: true
        }
    });
    
    Bee.center = Ext.create('Ext.tab.Panel', {
        id: 'main-viewport-center',
        region: 'center',
        deferredRender: false,
        activeTab: 0,
        margins: '0 5 3 0',
        items: [Bee.home]
    });
    
    Bee.center.loadMask = new Ext.LoadMask(Bee.center, {
        msg: "加载中，请稍候..."
    });
    
    Bee.viewport = Ext.create('Ext.Viewport', {
        id: 'main-viewport',
        layout: 'border',
        items: [Bee.north, Bee.west, Bee.center]
    });
    
    Bee.viewport.loadMask = new Ext.LoadMask(Bee.viewport, {
        msg: "加载中，请稍候..."
    });
    
    Bee.viewport.loadMask.show();
    
    Ext.Ajax.request({
        method: 'post',
        url: 'sm/findResource.do',
        params: {
            parentSid: 0
        },
        success: function(response){
            var data = Ext.JSON.decode(response.responseText);
            for (var i = 0; i < data.length; i++) {
                Bee.west.add(Ext.create("Ext.tree.Panel", {
                    title: data[i].text,
                    store: Ext.create('Ext.data.TreeStore', {
                        root: data[i],
                        fields: ['id', 'text', 'link', 'leaf', 'expanded', 'children']
                    }),
                    autoScroll: true,
                    rootVisible: false,
                    listeners: {
                        'itemclick': function(a, b){
                            Bee.tabPanel(b.data);
                        }
                    }
                }));
                Bee.west.doLayout();
            }
            Bee.viewport.loadMask.hide();
        },
        failure: function(request){
        }
    });
    
});
